package org.an.proj.contacts.ui.base;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.Utils;
import me.imid.swipebacklayout.lib.app.SwipeBackActivityBase;
import me.imid.swipebacklayout.lib.app.SwipeBackActivityHelper;

/**
 * Created by Fcy on 2016/10/16.<br/>
 * 侧滑回退Activity基类
 * T has no effect on non-translucent activities or on activities
 * with the {@link android.R.attr#windowIsFloating} attribute.
 */
public class BaseSwipeBackActivity extends FragmentActivity implements SwipeBackActivityBase {
  private SwipeBackActivityHelper mHelper;

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mHelper = new SwipeBackActivityHelper(this);
    mHelper.onActivityCreate();
    getSwipeBackLayout().setEdgeSize(300);
    // //底层阴影颜色
    getSwipeBackLayout().setScrimColor(Color.RED);
    //对横向滑动手势的敏感程度。0为迟钝 1为敏感
    getSwipeBackLayout().setSensitivity(this,0.5f);
    // 关闭Activity的临界点，滑动宽度的比例
    getSwipeBackLayout().setScrollThresHold(0.5f);

  }

  @Override protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    mHelper.onPostCreate();
  }

  @Override public View findViewById(int id) {
    View v = super.findViewById(id);
    if (v == null && mHelper != null) return mHelper.findViewById(id);
    return v;
  }

  @Override public SwipeBackLayout getSwipeBackLayout() {
    return mHelper.getSwipeBackLayout();
  }

  @Override public void setSwipeBackEnable(boolean enable) {
    getSwipeBackLayout().setEnableGesture(enable);
  }

  @Override public void scrollToFinishActivity() {
    Utils.convertActivityToTranslucent(this);
    getSwipeBackLayout().scrollToFinishActivity();
  }
}
